import Vue from "vue";
import Router from "vue-router";
import Index from "@/components/index/Index";
import copyRight from "@/components/copyRight/copyRight";
import { resolve } from "url";
Vue.use(Router);
// let router = new Router({

// })

// router.beforeEach((to, from, next) => {
//     if(to.meta.path == '/login'){
//         if(localStorage.setItem('user') != null){

//         }
//     }
// })
const router = new Router({
  routes: [
    {
      path: "/",
      name: "Index",
      component: Index,
      meta: {
        requireAuth: true
      },
    },
    {
      path: "/Articl/:id",
			name: "Articl",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/articlText/articl.vue"], resolve)
    },
    {
      path: "/ArticList/:type",
			name: "ArticList",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/articlText/articlLists.vue"], resolve)
    },
    {
      path: "/ENTER",
			name: "ENTER",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/index/SuperEnter/enters"], resolve)
    },
    {
      path: "/UserInfo",
			name: "UserInfo",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/UserSever/UserInfor/UserInfo"], resolve),
      children: [
        {
          path: "/UserInfo/UserBase",
					name: "UserBase",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require(["../components/UserSever/UserInfor/UserBase"], resolve)
        },
        {
          path: "/UserInfo/UserPay",
					name: "UserPay",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require(["../components/UserSever/UserInfor/UserPay"], resolve)
        },
        {
          path: "/UserInfo/UserMussion",
					name: "UserMussion",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require(["../components/UserSever/UserInfor/UserMussion"], resolve)
        }
      ]
    },
    // 内容自动接入新增
    {
      path: "/automaticAdd",
			name: "automaticAdd",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/copyRight/automaticAdd/automaticAdd"], resolve)
    },
    // 版本内容仓库新增
    {
      path: "/warehouseAdd",
			name: "warehouseAdd",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/copyRight/warehouse/warehouseAdd"], resolve)
    },
    // 版本内容仓库模块
    {
      path: "/copyRight",
			name: "copyRight",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/copyRight/copyRight"], resolve),
      children: [
        // 内容自动接入
        {
          path: "/copyRight/automaticAccess",
					name: "automaticAccess",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require([
              "../components/copyRight/automaticAssess/automaticAccess"
            ], resolve)
        },
        // 版权内存仓库
        {
          path: "/copyRight/warehouse",
					name: "warehouse",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require(["../components/copyRight/warehouse/warehouse"], resolve)
        },
        // 著作权证书管理
        {
          path: "/copyRight/copyrightManage",
					name: "copyrightManage",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require([
              "../components/copyRight/copyrightManage/copyrightManage"
            ], resolve)
        },
        // 著作权代办
        {
          path: "/copyRight/copyrightAgency",
					name: "copyrightAgency",
					meta: {
						requireAuth: true
					},
          component: resolve =>
            require([
              "../components/copyRight/copyrightAgency/copyrightAgency"
            ], resolve)
        }
      ]
    },
    // 著作权证书详情新增
    {
      path: "/CertificateDetails",
			name: "CertificateDetails",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require([
          "../components/copyRight/copyrightManage/CertificateDetails"
        ], resolve)
    },
    // 著作权证书详情
    {
      path: "/copyrightCertDetail",
			name: "copyrightCertDetail",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require([
          "../components/copyRight/copyrightManage/copyrightCertDetail"
        ], resolve)
    },
    //著作权代办新增
    {
      path: "/agencyAdd",
			name: "agencyAdd",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/copyRight/copyrightAgency/agencyAdd"], resolve)
    },
    //版权内存仓库详情
    {
      path: "/warehouseDetail",
			name: "warehouseDetail",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/copyRight/warehouse/warehouseDetail"], resolve)
    },
    // 著作权代办详情
    {
      path: "/copyrightAgencyDetail",
			name: "copyrightAgencyDetail",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require([
          "../components/copyRight/copyrightAgency/copyrightAgencyDetail"
        ], resolve)
    },
    // 法务咨询列表
    {
      path: "/lawConsultionList",
			name: "lawConsultionList",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/lawConsultion/lawConsultionList"], resolve)
    },
    // 我的近期预约列表
    {
      path: "/AppointmentList",
			name: "AppointmentList",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/lawConsultion/AppointmentList"], resolve)
    },

    {
      path: "/OrderXq",
			name: "OrderXq",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/UserSever/UserCommen/OrderXq"], resolve)
    },
    {
      path: "/FpXiangq",
			name: "FpXiangq",
			meta: {
        requireAuth: true
      },
      component: resolve =>
        require(["../components/UserSever/UserCommen/FpXiangq"], resolve)
    },
    ////登录
    {
      path: "/Login",
      name: "Login",
      component: resolve => require(["../components/login/login"], resolve)
    }
  ]
});
router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requireAuth)) {
    if (localStorage.getItem("user") != 'null') {
      next();
    } else {
      next({
        path: "/Login",
        query: { redirect: `${to.fullPath}` }
      });
    }
  } else {
    next();
  }
});
export default router;
